package com.dave.gd.core.util;

import com.dave.gd.common.util.StringUtils;
import com.dave.gd.core.base.entity.IAttrSpec;

public class AttrStatus {
    private IAttrSpec attrSpec;
    
    private Object    oldValue;
    
    private Object    newValue;
    
    //    private EAttrState state;
    
    public IAttrSpec getAttrSpec() {
        return attrSpec;
    }
    
    public void setAttrSpec(IAttrSpec attrSpec) {
        this.attrSpec = attrSpec;
    }
    
    public Object getOldValue() {
        return oldValue;
    }
    
    public void setOldValue(Object oldValue) {
        this.oldValue = oldValue;
    }
    
    public Object getNewValue() {
        return newValue;
    }
    
    public void setNewValue(Object newValue) {
        this.newValue = newValue;
    }
    
    public EAttrState getState() {
        if (this.getOldValue() == null || StringUtils.isNullOrEmpty(this.getOldValue())) {
            if (this.getNewValue() == null || StringUtils.isNullOrEmpty(this.getNewValue())) {
                return EAttrState.INIT;
            } else {
                return EAttrState.CHANGGED;
            }
        } else {
            if (this.getNewValue() == null || StringUtils.isNullOrEmpty(this.getNewValue())) {
                return EAttrState.CHANGGED;
            } else {
                if (this.oldValue.equals(this.getNewValue())) {
                    return EAttrState.INIT;
                } else {
                    return EAttrState.CHANGGED;
                }
            }
        }
    }
    
    //    public void setState(EAttrState state) {
    //        this.state = state;
    //    }
    
    @Override
    public String toString() {
        return "[" + "attrSpec:" + this.getAttrSpec() + ";-;" + "oldValue:" + this.getOldValue()
            + ";-;" + "newValue:" + this.getNewValue() + ";-;" + "state:" + this.getState() + "]";
    }
}
